package thread.state;

public class ThreadStateTransfer2 {
    public static void main(String[] args) {
        final Object object = new Object();
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (object) {
                        try {
                            //修改这个sleep
                            //Thread.sleep(1000);
                            System.out.println("t1 wait 之前");
                            object.wait();
                            System.out.println("t1 收到了通知");
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                }
            }
        }, "t1");
        t1.start();
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (object) {
                    System.out.println("t2 工作打印，hehe");
                    object.notify();
                }
            }
        }, "t2");
        t2.start();
        System.out.println("t1 的状态："+t1.getState());
        System.out.println("t2 的状态："+t2.getState());

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("t2 的状态："+t2.getState());
    }
}
